﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Collections;

namespace CaliburnWpf.Views.Infrastructure
{
    public class ViewHelper:DependencyObject 
    {
        public static readonly DependencyProperty SelectedPathProperty = DependencyProperty.RegisterAttached("SelectedPath", typeof(object[]), typeof(ViewHelper), new PropertyMetadata(new object[0]));
        public static object[] GetSelectedPath(TreeView w)
        {
            return (object[])w.GetValue(SelectedPathProperty);
        }
        public static void SetSelectedPath(TreeView w, object[] path)
        {
            w.SetValue(SelectedPathProperty, path);
        }


        public static object[] GetPathFor(TreeViewItem item)
        {
            ArrayList list = new ArrayList();
            FrameworkElement curr = item;
            while (curr != null)
            {
                list.Add(curr.DataContext);
                curr = (FrameworkElement)ItemsControl.ItemsControlFromItemContainer(curr);
            }

            list.Reverse();
            return list.ToArray();
        }

    }
}
